﻿using System;
using System.Collections.Generic;
using System.Text;

namespace gChartSharp
{
    /// <summary>
    /// http://code.google.com/apis/chart/#chart_size
    /// </summary>
    public class SizeParam : IChartParam
    {

        /// <summary>
        /// The API name of the parameter
        /// </summary>
        public string Name { get { return "chs"; } }


        /// <summary>
        /// The width of the graph
        /// </summary>
        public int Width { get; set; }


        /// <summary>
        /// The height of the graph
        /// </summary>
        public int Height { get; set; }


        /// <summary>
        /// Default constructor
        /// </summary>
        public SizeParam()
        {
            this.Width = 600;
            this.Height = 500;
        }


        /// <summary>
        /// Constructor to set height and width
        /// </summary>
        /// <param name="height"></param>
        /// <param name="width"></param>
        public SizeParam(int width, int height)
        {
            this.Width = width;
            this.Height = height;
        }


        /// <summary>
        /// The text to pass to the API
        /// </summary>
        public string Render()
        {
            if (this.Height * this.Width > 300000)
                throw new ParamException("Maximum size in pixels cannot exceed 300,000.");

            StringBuilder sb = new StringBuilder();
            sb.Append(String.Format("&{0}={1}x{2}", this.Name, this.Width, this.Height));
            return sb.ToString();
        }
    }
}
